home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Demos / AppMaker 2.0b3 / Demo AppMaker 1.5 / Demo AppMaker™ / Demo AppMaker™.rsrc / TmPT_111_Data < prev    next >
Encoding:
Text File  |  1992-04-08  |  4.3 KB  |  201 lines

  1. { %filename% -- data access methods}
  2. { Created %date% %time% by AppMaker}
  3.  
  4. {    This module contains data structures to access the data in your}
  5. {    document's file(s). The intent is to isolate the details of the}
  6. {    data representation into this module and to provide accessor}
  7. {    functions for reading/writing logical pieces of the data.}
  8. {    For your application, you will probably rewrite most of this.}
  9. {    This module will not be regenerated by AppMaker unless you delete it.}
  10.  
  11. Unit %unitname%;
  12. Interface
  13.  
  14. Uses
  15.     TCL,
  16.     AMCL,
  17.     ResourceDefs;
  18.  
  19. {Define the creator type and file type for your application:}
  20. const
  21.     kSignature        = 'XXXX';
  22.     kFileType        = 'TEXT';
  23.  
  24. type
  25.     C%appname%Data    = object (CDataFile) 
  26.         hasFile:        boolean;
  27.         itsDocument:    CDocument;
  28.  
  29.     {define your own internal data structures:}
  30.         itsData:        Handle;
  31.  
  32.  
  33.         Procedure I%appname%Data    (theDocument:    CDocument);
  34.         Procedure Free;        override;
  35.  
  36.         Procedure Close;    override;
  37.         Procedure OpenData    (permission:    SignedByte);
  38.         Function  Save: Boolean;
  39.         Function  SaveAs    (macSFReply:    SFReply): Boolean;
  40.         Procedure Revert;
  41.  
  42.         Procedure ReadData;
  43.         Function  WriteData: Boolean;
  44.         Procedure DisposeData;
  45.  
  46.     {accessor functions, replace these with application-specific functions:}
  47.         Procedure Get%appname%;
  48.         Procedure Put%appname%;
  49.         Procedure Add%appname%;
  50.         Procedure Delete%appname%;
  51.  
  52.     end; {C%Appname%Data}
  53.  
  54. {----------}
  55. Implementation
  56.  
  57. {----------}
  58. Procedure C%appname%Data.I%appname%Data    (theDocument:    CDocument);
  59. Begin
  60.     inherited IDataFile;
  61.     hasFile := false;
  62.     itsDocument := theDocument;
  63.  
  64.     {your application-specific initialization}
  65.     itsData := nil;
  66.  
  67. End; {I%appname%Data}
  68.  
  69. {----------}
  70. Procedure C%appname%Data.Free;
  71. Begin
  72.     DisposeData;
  73.     inherited Free;
  74. End; {Free}
  75.  
  76. {----------}
  77. Procedure C%appname%Data.OpenData    (permission:    SignedByte);
  78. Begin
  79.     Open (permission);
  80.     hasFile := true;
  81.  
  82.     ReadData;
  83.  
  84. End; {OpenData}
  85.  
  86. {----------}
  87. Procedure C%appname%Data.Close;
  88. Begin
  89.     inherited Close;
  90.     hasFile := false;
  91.     {don't DisposeData because data may be needed by SaveAs}
  92. End; {Close}
  93.  
  94. {----------}
  95. Function C%appname%Data.Save: Boolean;
  96. Begin
  97.     if hasFile then begin
  98.         Save := WriteData;
  99.     end else begin
  100.         {shouldn't be called in this case}
  101.         Save := false;
  102.     end;
  103. End; {Save}
  104.  
  105. {----------}
  106. Function C%appname%Data.SaveAs    (macSFReply:    SFReply): Boolean;
  107. var
  108.     ignoreErr:        OSErr;
  109. Begin
  110. { If all of your data is in memory, then just close the current file}
  111. { create and open a file, then save your data into the new file}
  112.  
  113. { If some of your data is in the current file and not in memory,}
  114. { you may have to create and open the new file,}
  115. { copy data from the current file to the new file,}
  116. { close the current file,}
  117. { then save your data into the new file}
  118.  
  119.     if hasFile then begin
  120.         Close;
  121.     end;
  122.     SFSpecify (macSFReply);
  123.     ignoreErr := HDelete (volNum, dirID, name);    {in case already exists}
  124.     CreateNew (gSignature, kFileType);
  125.     Open (fsRdWrPerm);
  126.     hasFile := true;
  127.  
  128.     SaveAs := Save;
  129. End; {SaveAs}
  130.  
  131. {----------}
  132. Procedure C%appname%Data.Revert;
  133. Begin
  134.     DisposeData;
  135.     if hasFile then begin
  136.         ReadData;
  137.     end;
  138. End; {Revert}
  139.  
  140.  
  141. { The next few methods are for transferring data between the }
  142. { data file and your internal data structures, and for disposing}
  143. { your data structures. They are called by Open, Close, etc.}
  144. { Replace their bodies with whatever is suitable for your application}
  145.  
  146. { define internal data structures to describe the file format:}
  147. type
  148.     fileData        = record
  149.         stuff:            integer;
  150.     end;
  151.  
  152. {----------}
  153. Procedure C%appname%Data.ReadData;
  154. Begin
  155.     itsData := ReadAll;
  156. End; {ReadData}    
  157.  
  158. {----------}
  159. Function C%appname%Data.WriteData: Boolean;
  160. Begin
  161.     WriteAll (itsData);
  162.     WriteData := true;
  163. End; {WriteData}    
  164.  
  165. {----------}
  166. Procedure C%appname%Data.DisposeData;
  167. Begin
  168.     if itsData <> nil then begin
  169.         DisposHandle (itsData);
  170.         itsData := nil;
  171.     end;
  172. End; {DisposeData}
  173.  
  174.  
  175. { The remaining methods are for accessing your data as logical chunks.}
  176. { These are just models for your own accessor functions;}
  177. { they aren't called by any AppMaker-generated code.}
  178. { Replace them with whatever is suitable for your application.}
  179.  
  180. {----------}
  181. Procedure C%appname%Data.Get%appname%;
  182. Begin
  183. End; {Get%appname%}
  184.  
  185. {----------}
  186. Procedure C%appname%Data.Put%appname%;
  187. Begin
  188. End; {Put%appname%}
  189.  
  190. {----------}
  191. Procedure C%appname%Data.Add%appname%;
  192. Begin
  193. End; {Add%appname%}
  194.  
  195. {----------}
  196. Procedure C%appname%Data.Delete%appname%;
  197. Begin
  198. End; {Delete%appname%}
  199.  
  200. End. {%unitname%}
  201.